package org.marvell.tests;

import org.junit.Before;
import org.junit.Test;
import org.marvell.infra.NikolaSO;

import jsystem.extensions.analyzers.text.FindText;
import jsystem.extensions.analyzers.text.GetIntCounter;
import jsystem.extensions.report.html.Report;
import jsystem.framework.TestProperties;
import junit.framework.SystemTestCase4;

public class NikolaCLIOperations extends SystemTestCase4 {
	
	NikolaSO nikola;
	private String expectedVersion;
	private int expectedUtil;
	
	@Before
	public void loadSO() throws Exception{
		nikola = (NikolaSO)system.getSystemObject("nikola");
	}
	
	@Test
	@TestProperties(name="Validate SW Version",paramsInclude={"expectedVersion"})
	public void validateSWVersion() throws Exception{
		report.addProperty("Funcion Name", "Validate SW Version");
		String version = nikola.showVersion();
		analyzer.setTestAgainstObject(version);
		analyzer.analyze(new FindText(expectedVersion));
	}
	
	@Test
	@TestProperties(name="Validate CPU Utilization",paramsInclude={"expectedUtil"})
	public void validateCPUUtilization() throws Exception{
		report.addProperty("Funcion Name", "Validate CPU Utilization");
		String cpuUtilization = nikola.executeCliCommand("show cpu utilization");
		analyzer.setTestAgainstObject(cpuUtilization);
		GetIntCounter cpu = new GetIntCounter("five seconds");
		analyzer.analyze(cpu);
		int actualCPU = cpu.getCounter();
		if (expectedUtil==actualCPU){
			report.report("The CPU for five seconds was "+actualCPU+" as Excpected");
		}else{
			report.report("The CPU for five seconds was "+actualCPU+" and not "+expectedUtil+ " as Excpected",report.FAIL);
		}
		
	}

	public int getExpectedUtil() {
		return expectedUtil;
	}

	public void setExpectedUtil(int expectedUtil) {
		this.expectedUtil = expectedUtil;
	}

	public String getExpectedVersion() {
		return expectedVersion;
	}

	public void setExpectedVersion(String expectedVersion) {
		this.expectedVersion = expectedVersion;
	}


}
